#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>


int main(void)
{
	int i;
	int fds[6];
	int led_cmd = 0;
	char name[256];
	for(i = 0; i < 6; i++)
	{
		memset(name, 0x00, sizeof(name));
		sprintf(name, "/dev/led_drv%d", i+1);
		fds[i] = open(name, O_RDWR);
		if(fds[i] < 0)
		{
			perror("open");
			goto open_err;
		}
	}
	while(1)
	{
		for(i = 0; i < 6; i++)
		{
			write(fds[i], &led_cmd, sizeof(led_cmd));
		}
		sleep(1);
		led_cmd = !led_cmd;
	}
	for(i = 0; i < 6; i++)
	{
		close(fds[i]);
	}
	return 0;

	open_err:
		for(; i > 0; i--)
		{
			close(fds[i-1]);
		}
	return -1;
}
